package game.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import common.controller.base.BaseController;
import common.model.enums.ClassificationTypeEnum;
import common.model.po.GCreature;
import common.model.request.base.PaginationRequest;
import common.model.response.base.Result;
import game.model.request.SaveCreatureRequest;
import game.model.request.SearchCreatureRequest;
import game.model.vo.SearchCreatureVo;
import game.service.GClassificationService;
import game.service.GCreatureService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 前端控制器
 *
 * @author 米泽鹏
 * @since 2023-11-28 下午 06:19
 */
@Api(tags = "生物管理")
@RestController
@RequestMapping("/game/g-creature")
public class GCreatureController extends BaseController {

	@Resource
	private GCreatureService service;
	@Resource
	private GClassificationService classificationService;

	@ApiOperation(value = "生物分页查询", notes = "生物分页查询")
	@PostMapping("/readOnly/searchCreatureByPage")
	public Result<Page<SearchCreatureVo>> searchCreatureByPage(@ApiParam(value = "生物分页查询请求", required = true) @RequestBody @Validated PaginationRequest<SearchCreatureRequest, GCreature> paginationRequest) {
		Page<SearchCreatureVo> data = service.searchCreatureByPage(paginationRequest);
		return successWithData(data);
	}

	@ApiOperation(value = "生物新增或更新", notes = "生物新增或更新")
	@PostMapping("/saveCreature")
	public Result<?> saveCreature(@ApiParam(value = "生物新增或更新请求", required = true) @RequestBody @Validated SaveCreatureRequest request) {
		return service.saveCreature(request);
	}

	@ApiOperation(value = "生物删除", notes = "生物删除")
	@DeleteMapping("/deleteCreature/{id}")
	public Result<?> deleteCreature(@ApiParam(value = "生物id", required = true) @PathVariable Long id) {
		return service.deleteCreature(id);
	}

	@ApiOperation(value = "获取全部分类（级联选择器）", notes = "获取全部分类（级联选择器）")
	@PostMapping("/readOnly/getCreatureCascadeClassification")
	public Result<?> getCreatureCascadeClassification() {
		return successWithData(classificationService.getCascadeClassification(ClassificationTypeEnum.CREATURE));
	}

}
